<?php
	#############################################################################################
	# Programmer: สมบูรณ์  กองลี																#
	# Email		: hugo8xx@hotmail.com.															#
	#############################################################################################

	function getUserIP()
	{
		return $_SERVER['REMOTE_ADDR'];
	}

	function getUserIPX()
	{
		return $_SERVER['HTTP_X_FORWARDED_FOR'];
	}

	function getUserAgent()
	{
		return $_SERVER['HTTP_USER_AGENT'];
	}

	function getUserRef()
	{
		return $_SERVER['HTTP_REFERER'];
	}


	function force_download ($data, $name, $mimetype='', $filesize=false) {
		// File size not set?
		if ($filesize == false OR !is_numeric($filesize)) {
			$filesize = strlen($data);
		}

		// Mimetype not set?
		if (empty($mimetype)) {
			$mimetype = 'application/octet-stream';
		}

		// Make sure there's not anything else left
		ob_clean_all();

		// Start sending headers
		header("Pragma: public"); // required
		header("Expires: 0");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		header("Cache-Control: private",false); // required for certain browsers
		header("Content-Transfer-Encoding: binary");
		header("Content-Type: " . $mimetype);
		header("Content-Length: " . $filesize);
		header("Content-Disposition: attachment; filename=\"" . $name . "\";" );

		// Send data
		echo $data;
		die();
	}

	function ob_clean_all () {
		$ob_active = ob_get_length () !== false;
		while($ob_active) {
			ob_end_clean();
			$ob_active = ob_get_length () !== false;
		}

		return true;
	}

	function isAJAX() {
		return (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
	}
?>